#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

class Solution{
    public:
    //MyAnswer
    int ans1(vector<int>& num){
        int length = num.size();
        int p = 0;
        while(p < length-1){
            if(num[p] == num[p+1]){
                int temp = num[p+1];
                for(int i = p+1; i != length-1; i++){
                    num[i] = num[i+1];
                }
                num.pop_back();
                length--;
            }
            else{
                p++;
            }
        }
        return num.size();
    }
    //双指针
    int ans2(vector<int>& num){
        int length = num.size();
        int p1 = 0;
        if(length > 1){
            for(int i = 1; i != length; i++){
                if(num[p1] != num[i]){
                    num[p1+1] = num[i];
                    p1++;
                }
            }
        }     
        return p1 + 1;
    }

    void show(vector<int> &num){
        int length = num.size();
        cout << "[" << ends;
        for(int i = 0; i != length-1; i++){
            cout << num[i] << "," << ends;
        }
        cout << num[length-1] << "]" << endl;
    }
};

void test1(){
    vector<int> num = {1, 1};

    Solution s;
    //int ret = s.ans1(num);
    int ret = s.ans2(num);
    cout << ret << endl;
    s.show(num);
}

void test2(){
    vector<int> num = {0, 0, 1, 1, 1, 2, 2, 3, 3, 4};

    Solution s;
    //int ret = s.ans1(num);
    int ret = s.ans2(num);
    cout << ret << endl;
    s.show(num);
}
int main(void){
    test1();
    test2();

    return 0;
}